package com.garlic.face.jlf.transaction.balance;

import android_serialport_api.SerialPort;

//20180904 cl 修改 指示灯只有红蓝两色。蓝色表示正常，红色表示异常
public class LampUtil {
    static String close_red = "fe0500000000d9c5";
    static String close_blue = "fe05000200007805";
    //    static String close_yellow = "fe05000100008805";
//    static String close_green = "fe05000200007805";
    static String open_red = "fe050000ff009835";
    static String open_blue = "fe050002ff0039f5";
//    static String open_yellow = "fe050001ff00c9f5";
//    static String open_green = "fe050002ff0039f5";

    public static void LampInit(SerialPortFunction serialPortFunction){
        LampAlarm(serialPortFunction, 0, 1, 0);
        //Thread.Sleep(2000);
        LampAlarm(serialPortFunction, 1, 1, 0);
    }

    public static void LampClose(SerialPortFunction serialPortFunction)
    {
        try
        {
            serialPortFunction.sendLight(close_red);
            serialPortFunction.sendLight(close_blue);
//            serialPortFunction.sendLight(close_green);
//            serialPortFunction.sendLight(close_yellow);

        }
        catch (Exception ex)
        {
            ex.getStackTrace();
        }
    }

    /// <summary>
    /// 控制警示灯
    /// lampindex：0-红灯；1-蓝灯
    /// lampstate：0-关闭；1-打开；2-闪烁
    /// sound：0-关闭；1～4声音序号
    /// </summary>
    /// <param name="lampindex">序号：0-红灯；1-蓝灯</param>
    /// <param name="lampstate">状态：0-关闭；1-打开；2-闪烁</param>
    /// <param name="sound">声音：0-关闭；1～4声音序号</param>
    /// <returns></returns>
    public static void LampAlarm(SerialPortFunction serialPortFunction, int lampindex, int lampstate, int sound)
    {
        new Thread(new Runnable() {
            @Override
            public void run() {
                switch (lampindex){
                    case 0://红灯
                        if(lampstate == 1 || lampstate == 2){
                            //红灯开 蓝灯关
                            serialPortFunction.sendLight(open_red);
                            try {
                                Thread.sleep(1000);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                            serialPortFunction.sendLight(close_blue);
                        }
                        else{
                            //红灯关
                            serialPortFunction.sendLight(close_red);
                        }
                        break;
                    case 1://蓝灯
                        if(lampstate ==  1 || lampstate == 2){
                            //蓝灯开 红灯关
                            serialPortFunction.sendLight(open_blue);
                            try {
                                Thread.sleep(1000);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                            serialPortFunction.sendLight(close_red);
                        }
                        else{
                            //蓝灯关
                            serialPortFunction.sendLight(close_blue);
                        }
                        break;
                }
            }
        }).start();

    }

//    /// <summary>
//    /// 控制警示灯
//    /// lampindex：0-红灯；1-黄灯；2-绿灯
//    /// lampstate：0-关闭；1-打开；2-闪烁
//    /// sound：0-关闭；1～4声音序号
//    /// </summary>
//    /// <param name="lampindex">序号：0-红灯；1-黄灯；2-绿灯</param>
//    /// <param name="lampstate">状态：0-关闭；1-打开；2-闪烁</param>
//    /// <param name="sound">声音：0-关闭；1～4声音序号</param>
//    /// <returns></returns>
//    public static void LampAlarm(SerialPortFunction serialPortFunction, int lampindex, int lampstate, int sound)
//    {
//        switch (lampindex){
//            case 0://红灯
//                if(lampstate == 1 || lampstate == 2){
//                    //红灯开 黄灯关 绿灯关
//                    serialPortFunction.sendLight(open_red);
//                    serialPortFunction.sendLight(close_yellow);
//                    serialPortFunction.sendLight(close_green);
//                }
//                else{
//                    //红灯关
//                    serialPortFunction.sendLight(close_red);
//                }
//                break;
//            case 1://黄灯
//                if(lampstate ==  1 || lampstate == 2){
//                    //黄灯开 红灯关 绿灯关
//                    serialPortFunction.sendLight(open_yellow);
//                    serialPortFunction.sendLight(close_red);
//                    serialPortFunction.sendLight(close_green);
//                }
//                else{
//                    //黄灯关
//                    serialPortFunction.sendLight(close_yellow);
//                }
//                break;
//            case 2://绿灯
//                if(lampstate == 1 || lampstate == 2){
//                    //绿灯开 黄灯关 红灯关
//                    serialPortFunction.sendLight(open_green);
//                    serialPortFunction.sendLight(close_yellow);
//                    serialPortFunction.sendLight(close_red);
//                }
//                else {
//                    //绿灯关
//                    serialPortFunction.sendLight(close_green);
//                }
//        }
//    }
}
